<extend name="Public/layout"/>
<block name="head">
<link rel="stylesheet" href="__PUBLIC__css/change-phone.css">
<style type="text/css">
.footer{
    display: none;
}
</style>
</block>
<block name="main">
  
    <div class="form">
        <div class="form-group">
            <input type="text" name="phone" class="phone-text" placeholder="请输入您的手机号码">
        </div>
        <div class="form-group">
            <input type="text" name="code" class="phone-text" placeholder="请输入验证码">
            <div class="phone-text-wrapper">
                <button class="get-verify-code" onclick="getcode()">获取验证码</button>
            </div>
        </div>
    </div>
    <div class="btn-wrapper">
        <a href="javascript:" onclick="sub()">保存</a>
    </div>
</block>
 <block name="js">
 <script type="text/javascript">
 function sub(){
    var phone = $('input[name="phone"]').val();
    var code = $('input[name="code"]').val();

     if (phone == '' || phone == undefined || phone == null) {
         layer.closeAll();
         layer.open({
             content: '请输入手机号码'
             ,skin: 'msg'
             ,time: 2
         });
         return
     }

     if (!/^\d+$/.test(phone)) {
         layer.closeAll();
         layer.open({
             content: '手机号码必须为数字'
             ,skin: 'msg'
             ,time: 2
         });
         $('input[name="phone"]').val('')
         return
     }

    $.post('{:U("Person/change_phone_end")}',{
        phone:phone,
        code:code
    },function(res){
        if(res.err==0){
            location.href="/Home/Person/index"
        }else{
            layer.open({
                content:res.msg
                ,skin: 'msg'
                ,time: 1 //2秒后自动关闭
            });
        }
    })
    

}
    function getcode(){
        event_send_sms()
         
    }

          //验证码计时
    var timer = 60;
    function codeTimer()
    {
        timer--;
        if(timer > 0){
            $('.get-verify-code').text( timer + '秒后可重发!');
            $('.get-verify-code').attr("send",1);
            setTimeout('codeTimer()', 1000);
        }else{
            $('.get-verify-code').text('获取验证码');
            $('.get-verify-code').attr("send",0);
            timer = 60;
        }
    }

    //发送短信
    function event_send_sms(){
        var phone = $('input[name="phone"]').val();
        var postData={
            role:3,
            phone:phone,
            val:0
        }
        if(timer >= 60){
                $(this).attr('disabled', 'disabled');
                $.ajax({
                    url:'/Home/Sms/change_phone_sms',
                    data:postData,
                    type:"post",
                    dataType:"json",
                    success:function(d){
                        if(d.err == 0){
                            codeTimer();
                        }else{
                            layer.open({
                                content:d.msg
                                ,skin: 'msg'
                                ,time: 1 //2秒后自动关闭
                            });
                        }
                    }
                });
            
        } 
    }

 
 </script>
 </block>